<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Break - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The Break statement exits (terminates) any type of loop statement." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Break</h1>
<p>Exits (terminates) any type of <a href="../Language.htm#loop-statement">loop statement</a>.</p>
<pre class="Syntax"><span class="func">Break</span> <span class="optional">, LoopLabel</span></pre>

<h2>Parameters</h2>
<dl>
  <dt>LoopLabel <span class="ver">[AHK_L 59+]</span></dt>
  <dd><em>LoopLabel</em> identifies which loop this statement should apply to; either by <a href="../misc/Labels.htm">label name</a> or numeric nesting level. If omitted or 1, this statement applies to the innermost loop in which it is enclosed. <em>LoopLabel</em> must be a constant value - variables and expressions are not supported. If a <a href="../misc/Labels.htm">label</a> is specified, it must point directly at a <a href="../Language.htm#loop-statement">loop statement</a>.</dd>
</dl>

<h2>Remarks</h2>
<p>The use of Break and <a href="Continue.htm">Continue</a> are encouraged over <a href="Goto.htm">Goto</a> since they usually make scripts more readable and maintainable.</p>
<h2>Related</h2>
<p><a href="Continue.htm">Continue</a>, <a href="Loop.htm">Loop</a>, <a href="While.htm">While-loop</a>, <a href="For.htm">For-loop</a>, <a href="Block.htm">Blocks</a>, <a href="../misc/Labels.htm">Labels</a></p>

<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Loop
{
    <em>; ...</em>
    if (var &gt; 25)
        break
    <em>; ...</em>
    if (var &lt;= 5)
        continue
}</pre>
</div>

<div class="ex" id="ExBreakOuter">
<p><a href="#ExBreakOuter">#2</a>: Break the outer loop from within a nested loop.</p>
<pre>outer:
Loop 3
{
    x := A_Index
    Loop 3
    {
        if (x*A_Index = 6)
            break outer  <em>; Equivalent to <b>break 2</b> or <b>goto break_outer</b>.</em>
        MsgBox %x%,%A_Index%
    }
}
break_outer: <em>; For goto.</em>
</pre>
</div>

</body>
</html>
